<template>
  <div style="width: 400px">
    <el-form>

      <el-form-item label="名字" label-width="80px">
        <el-input v-model="fromdata.name" size="small" placeholder="请输入内容"></el-input>
        <!--还提供了 medium、small 和 mini 三种尺寸。-->
      </el-form-item>
      <el-form-item label="年龄" label-width="80px">
        <el-input v-model="fromdata.age" size="small" placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" label-width="80px">
        <el-input v-model="fromdata.email" size="small" placeholder="请输入内容"></el-input>
      </el-form-item>

      <el-button @click="resetFrom()">提交</el-button>

    </el-form>
  </div>

</template>

<script>

import axios from "axios";
import qs from 'qs';
import {sendMsg} from "../js/user/adduser";
import List from "./List";
import list from "./List";

let unHandler;

export default {
  name: "adduser",
  props: ['close'],
  inject: ['reload'],
  data() {
    return {
      fromdata: {},
      age: "20",
      /*   uname:'',
         age:'',
         email:'',*/
    }
  },
  methods: {

    resetFrom() {
      let that = this;
      var pam = this.fromdata/*{
        'id':'10',
        'name':this.uname,
        'age':this.age,
        'email':this.email,
      };*/
console.log(pam)
      //三种传值方法

      //后端用实体类接收,添加账号之类的时候便捷
      this.axios.post('http://localhost:8080/adduser', pam).then(function (res) {
        if (res.data == "1") {
          that.$message({message: '成功', type: 'success'})
          that.$props.close();
          that.reload();
        } else {
          that.$message.error('失败')
          that.$props.close();
        }
        /*console.log(res)*/
        /*sendMsg('add-imp',pam);//跨标签通信*/
      })
      /* //后端用HttpServletRequest接收,带一些别的参数时需要
       this.axios.post('http://localhost:8080/adduser2',qs.stringify(pam)).then(function (res){
         console.log(res)
       })*/

      //后端用HttpServletRequest接收
      /*       axios({
               methods: 'post',
               url:'http://localhost:8080/adduser2',
               params:pam,
             }).then(function (res){

             })*/
    }
  },


}


</script>
<style scoped>

</style>
